<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Module
 *
 * @author gemeijie
 */
class Libs_Admin_Module {

    protected static $_dbAdmin;

    /**
     * 数据库链接
     */
    public static function loadDb() {
        self::$_dbAdmin = Db_Admin::instance();
    }

    /*
     * 添加新类
     */
    public static function addModule(array $param){
        $moduleName = !empty ($param['modulename']) ? $param['modulename'] : '';
        
        if($moduleName == ''){
            return false;
        }

        self::loadDb();
        
        $sql = "insert into module_list(name, isdel) values ('$moduleName',0)";
        self::$_dbAdmin->query($sql);
    }


    /*
     *获取模块类列表   冲突了。。。。。。
     * 
     */
    public static function getModuleList(array $param){
        self::loadDb();
        $sql = "Select id, name  from module_list where isdel=0";
        $list = self::$_dbAdmin->get_results($sql);

        return $list;
    }
//    public static function getModuleList(array $param){
//        self::loadDb();
//        $subSql = '';
//        if(isset($param['moduleId']))$subSql   .= " and module_type in (".$param['moduleId'].") ";
//        if(isset($param['classId']))$subSql    .= " and classid in (".$param['classId'].") ";
//        if(isset($param['subclassId']))$subSql .= " and subclassid in (".$param['subclassId'].") ";
//        if(isset($param['id']))$subSql .= " and id in (".$param['id'].") ";
//        $sql = "Select id, name,subclassid from category_list where isdel=0 {$subSql} order by orderby desc,id asc ";
//        $list = self::$_dbAdmin->get_results($sql);
//
//        return $list;
//    }
    /*
     *获取模块类列表,返回select的option的
     */
    public static function getModuleSelect(array $param){
        $selVal = $param['selVal'];
        unset($param['selVal']);

        $dataArr = Libs_Admin_Category::getCategoryList($param);
        //$dataArr = Libs_Admin_Module::getModuleList($param);
        $optionStr = '';
        $dataArr2 = array();
        if($dataArr){
            foreach($dataArr as $d){
                if($param['type'] == 1){
                     $dataArr2[$d['classid']] = $d['name'];
                }else{
                     $dataArr2[$d['subclassid']] = $d['name'];
                }
            }
        }
        $optionStr = Libs_CommonHelper::showSelectOptions(array('data'=>$dataArr2,'selVal'=>$selVal));
        return $optionStr;
    }
    /*
     * 删除模块类
     */
    public static function delModule(array $param){
        $id = !empty ($param['id']) ? $param['id'] : 0;

        if($id == 0){
            return false;
        }

        self::loadDb();

        $sql = "update module_list set isdel=1 where id=$id";
        self::$_dbAdmin->query($sql);
    }

}

?>
